package com.jiangchao.annotationmvc.core.util;

import java.lang.reflect.Field;

import javax.servlet.http.HttpServletRequest;

public class FillBeanUtils {
	private FillBeanUtils() {

	}

	public static Object fillForm(HttpServletRequest request, String formPath)
			throws ClassNotFoundException, InstantiationException, IllegalAccessException {

		Class<?> clz = (Class<?>) Class.forName(formPath);
		Object object =  clz.newInstance();
		Field[] fields = clz.getDeclaredFields();
		for (Field field : fields) {
			field.setAccessible(true);
			field.set(object, request.getParameter(field.getName()));
			field.setAccessible(false);
		}

		return object;

	}

}
